﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace UnityEngine.Graphics
{
    public enum UIRendererType
    {
        AlphaBlend,
        OpaqueBlend,
        AlphaTestBlend,
        CustomBlend,
    }

    public class SpritePaletteRendererContainer : PaletteRendererContainer
    {
        public static readonly string ALPHA_BLEND = "AlphaBlend";
        public static readonly string OPAQUE_BLEND = "OpaqueBlend";
        public static readonly string ALPHA_TEST_BLEND = "AlphaTestBlend";
        public static readonly string CUSTOM_BLEND = "CustomBlend";

        private Dictionary<string, PaletteRenderer> _Renderers = new Dictionary<string, PaletteRenderer>();

        public SpritePaletteRendererContainer(Game game)
        {
            var alphaBlendSpriteBatch = new SpriteBatch(game.GraphicsDevice);
            _Renderers.Add(ALPHA_BLEND, new AlphaBlendSpriteRenderer(alphaBlendSpriteBatch));
            _Renderers.Add(OPAQUE_BLEND, new OpaqueBlendSpriteRenderer(alphaBlendSpriteBatch));
            _Renderers.Add(ALPHA_TEST_BLEND, new AlphaTestBlendSpriteRenderer(alphaBlendSpriteBatch));
            _Renderers.Add(CUSTOM_BLEND, new CusmtomBlendSpriteRenderer(alphaBlendSpriteBatch, game));
        }

        public override PaletteRenderer GetPaletteRenderer(string name)
        {
            return _Renderers[name];
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_Renderers != null)
                {
                    foreach (var c in this._Renderers.Values)
                        if (c != null)
                            c.Dispose();
                }
            }
            base.Dispose(disposing);
        }
    }
}
